<?php
/* @var $this PostController */
/* @var $model Post*/
$this->breadcrumbs = array(
   'Quản lý bài đăng' => '/admin/'.$this->id,
   'Đăng bài'
);

?>
<div class="form" id="<?php echo Yii::app()->controller->id . '-' . Yii::app()->controller->action->id?>">
<?php
   $form = $this->beginWidget('CActiveForm',array(
      'enableClientValidation' => true,
      'clientOptions'=>array(
   		'validateOnSubmit'=>true,
   	),
      'htmlOptions' => array(
         'class' => 'form-horizontal',
         'enctype' => 'multipart/form-data',
      ),
      'id' => Yii::app()->controller->id . '_' . Yii::app()->controller->action->id )
   );
?>
   <p class="note">Những dòng đánh dấu <span class="required">*</span> là bắt buộc.</p>

	<?php echo $form->errorSummary($model,'Kiểm tra lại các giá trị bạn vừa nhập vào'); 
      if($message != ''){
         echo CHtml::tag('div', array('class'=>'message-success'),$message);
      }
   ?>
   <input name="session_user" type="hidden" value="<?php echo $session_user?>"/>
   <input name="action_user" type="hidden" value="" id="action_user" />
   <div class="control-group">
      <?php echo $form->labelEx($model, 'post_title',array('class' => 'control-label'));?>
      <div class="controls">
         <?php echo $form->textField($model, 'post_title',array('style' => 'width:500px;'));?>
      </div>
   </div>
   <div class="control-group">
      <?php echo $form->labelEx($model, 'post_cat_id',array('class' => 'control-label'));?>
      <div class="controls">
         <?php echo $form->dropDownList($model, 'post_cat_id',$tree_cate);?>
      </div>
   </div>
   <div class="control-group">
      <?php echo $form->labelEx($model, 'post_vip',array('class' => 'control-label'));?>
      <div class="controls">
         <?php echo $form->checkBox($model, 'post_vip',$list_province);?>
      </div>
   </div>
   <div class="control-group">
      <?php echo $form->labelEx($model, 'post_prv_id',array('class' => 'control-label'));?>
      <div class="controls inline">
         <?php echo $form->dropDownList($model, 'post_prv_id',$list_province);?>
      </div>
      
      <?php echo $form->labelEx($model, 'post_dis_id',array('class' => 'control-label'));?>
      <div class="controls inline">
         <?php echo $form->dropDownList($model, 'post_dis_id',$list_distric);?>
      </div>
   </div>
   <div class="control-group">
      <?php echo $form->labelEx($model, 'post_prj_id',array('class' => 'control-label'));?>
      <div class="controls">
         <?php echo $form->dropDownList($model, 'post_prj_id',$list_project);?>
      </div>
   </div>
   <div class="control-group">
      <?php echo $form->labelEx($model, 'post_content',array('class' => 'control-label'));?>
      <div class="controls">
         <?php echo $form->textArea($model, 'post_content',array('class' => 'redactor'));?>
      </div>
   </div>
   <div class="control-group">
      <?php echo $form->labelEx($PostImage,'post_img',array('class' => 'control-label')); ?>
      <div class="controls">
      <input id="PostImage_attachments" type="file" name="PostImage[attachments][]" value="" multiple="multiple"/>
      </div>
   <div class="hint">Bạn có thể giữ Ctrl để tải nhiều ảnh lên cùng một lúc - Ảnh đầu tiên bạn chọn sẽ là ảnh đại diện</div>
   </div>
   
   <div class="control-group">
      <?php echo $form->labelEx($model, 'post_price',array('class' => 'control-label'));?>
      <div class="controls inline">
         <?php echo $form->textField($model, 'post_price',array('placeholder'=>'đ','class' => 'currency'));?>
      </div>
      <?php echo $form->labelEx($model, 'post_area',array('class' => 'control-label'));?>
      <div class="controls inline">
         <?php echo $form->textField($model, 'post_area',array('placeholder'=>'m²','class' => 'currency'));?>
      </div>
   </div>
   <div class="control-group">
      <?php echo $form->labelEx($model, 'post_address',array('class' => 'control-label'));?>
      <div class="controls inline">
         <?php echo $form->textField($model, 'post_address');?>
      </div>
      <?php echo $form->labelEx($model, 'post_phone_contact',array('class' => 'control-label'));?>
      <div class="controls inline">
         <?php echo $form->textField($model, 'post_phone_contact');?>
      </div>
   </div>
   <div class="control-group">
      <?php echo $form->labelEx($model, 'post_date_create',array('class' => 'control-label'));?>
      <div class="controls">
         <?php echo $form->textField($model, 'post_date_create',array('class' => 'datepicker','value' => is_null($model->post_date_create) ? date('d/m/Y',time()) : date('d/m/Y',$model->post_date_create)));?>
      </div>
   </div>
   
   <div class="control-group">
      <?php echo $form->labelEx($model, 'post_active',array('class' => 'control-label'));?>
      <div class="controls">
         <?php echo $form->checkBox($model, 'post_active',array('checked' => 'checked'));?>
      </div>
   </div>
   <div class="form-actions">
      <?php echo CHtml::submitButton('Lưu',array('class' => 'btn btn-info'))?>
      <?php echo CHtml::resetButton('Hủy',array('class' => 'btn btn-warning' ,'onclick' => 'window.history.go(-1)'))?>
	</div>
<?php $this->endWidget(); ?>
</div>
<script>
   $(document).ready(function(){
      $(".datepicker").datepicker({
         dateFormat:"dd/mm/yy",
         defaultDate: '<?php echo date('d/m/Y',time())?>',
      });
      
      $(".redactor").redactor({
         lang: 'vi',
         imageUpload: '<?php echo Yii::app()->request->hostInfo;?>/redactor/scripts/image_upload.php',
         plugins: ['fontsize']
      });
      
      $("#Post_post_prv_id").change(function(){
         var prv_id = $(this).val();
         data = {'prv_id':prv_id};
         success = function(data){
            $("#Post_post_dis_id").html(data);
         }
         handleAjax('/admin/district/SetDropListByPrvID','GET','',data,success);
      });
      
      $("#Post_post_dis_id").change(function(){
         var dis_id = $(this).val();
         data = {'dis_id':dis_id};
         success = function(data){
            $("#Post_post_prj_id").html(data);
         }
         handleAjax('/admin/project/SetDropListByDisID','GET','',data,success);
      });
   });
</script>